﻿<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <title>添加交接单</title>

    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet"/>
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link th:href="@{/erp/assets/css/codemirror.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}"/>
    <script th:src="@{/erp/js/jquery-1.9.1.min.js}"></script>
    <script th:src="@{/erp/assets/js/bootstrap.min.js}"></script>
    <script type="text/javascript" th:src="@{/erp/Widget/Validform/5.3.2/Validform.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.bootstrap.js}"></script>
    <script th:src="@{/erp/assets/js/typeahead-bs2.min.js}"></script>
    <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript"></script>
    <script th:src="@{/erp/assets/js/jquery-ui-1.10.3.custom.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.ui.touch-punch.min.js}"></script>
    <script th:src="@{/erp/assets/js/ace-elements.min.js}"></script>
    <script th:src="@{/erp/assets/js/ace.min.js}"></script>
    <script th:src="@{/erp/js/lrtk.js}" type="text/javascript"></script>
    <script th:src="@{/erp/assets/laydate/laydate.js}" type="text/javascript"></script>

</head>
<body>
<form>
    <div class="add_menber" id="add_menber_style">
        <ul class=" page-content">
            <li>
                <label class="label_name">订单编号：</label>
                <span class="add_name">
                        <select name='orderId' style='width:200px'>
                            <option value='' selected>请选择</option>
                            <option th:each="o : ${orderidlist}" th:value="${o.orderId}"
                                    th:text="${o.orderId}"></option>
                        </select>
                    </span>
                <div class="prompt r_f"></div>
            </li>
            <li>
                <label class="label_name">收货仓库：</label>
                <span class="add_name">
                        <select name='wareName' style='width:200px'>
                            <option value='' selected>请选择</option>
                            <option th:each="w : ${warelist}" th:value="${w.wareName}" th:text="${w.wareName}"></option>
                        </select>
                    </span>
                <div class="prompt r_f"></div>
            </li>
            <div class="prompt r_f"></div>
            <li><label class="label_name">入库数量：</label>
                <span class="add_name"><input name="num" type="text" class="text_add"/></span>
                <div class="prompt r_f"></div>
            </li>
            <li><label class="label_name">交接日期：</label>
                <span class="add_name"><input name="handoverDate" type="text" id="rksj" class="text_add laydate-icon"/></span>
                <div class="prompt r_f"></div>
            </li>
            <li><label class="label_name">交接人：</label>
                <span class="add_name"><input name="head" type="text" class="text_add" placeholder="请至少输入2个汉字"/></span>
                <div class="prompt r_f"></div>
            </li>
            <li><label class="label_name">备注：</label>
                <span class="add_name"><input name="remake" type="text" class="text_add"/></span>
                <div class="prompt r_f"></div>
            </li>
        </ul>
    </div>
</form>
<div style="margin:0 auto;width:200px;">
    <button class="btn btn-warning" id="adds">立即提交</button>
</div>


<script>

    //正整数验证
    function isPInt(str) {
        var g = /^[1-9]*[1-9][0-9]*$/;
        return g.test(str);
    }

    //正整数验证
    function isName(str) {
        var g = /^[\u4e00-\u9fa5]{2,6}$/;
        return g.test(str);
    }

    jQuery(function ($) {
        $('#adds').on('click', function () {
            var ids = $("select[name='orderId']").val();
            var wareNames = $("select[name='wareName']").val();
            var nums = $("input[name='num']").val();
            var date = $("input[name='handoverDate']").val();
            var heads = $("input[name='head']").val();
            if (ids == "") {
                layer.msg('请选择订单编号!', {icon: 5, time: 2000});
            } else {
                if (wareNames == "") {
                    layer.msg('请选择收货仓库!', {icon: 5, time: 2000});
                } else {
                    if (!isPInt(nums)) {
                        layer.msg('请输入数字,入库数量必须为大于0!', {icon: 5, time: 2000});
                    } else {
                        if (date == "") {
                            layer.msg('交接日期不能为空!', {icon: 5, time: 2000});
                        } else {
                            if (!isName(heads)) {
                                layer.msg('交接人不能为空，且只能为中文!', {icon: 5, time: 2000});
                            } else {
                                $.ajax({
                                        url: '/handover/add',
                                        contentType: "application/x-www-form-urlencoded; charset=utf-8",
                                        type: 'post',
                                        dataType: 'json',
                                        data: $('form').serialize(),
                                        success: function (e) {
                                            if (e.rs) {
                                                layer.msg('添加成功!',{icon: 1,time:2000});

                                                $('#find', window.parent.document).click();

                                                //关闭弹出窗
                                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                                parent.layer.close(index);//关闭弹出层
                                            }else {
                                                layer.msg('添加失败!',{icon: 1,time:2000});

                                                $('#find', window.parent.document).click();

                                                //关闭弹出窗
                                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                                parent.layer.close(index);//关闭弹出层
                                            }
                                        }
                                })
                            }
                        }
                    }
                }
            }
        });

    })

    laydate.render({
        elem: '#rksj',
        type: 'datetime',
        min: getNowFormatDate()
    });

    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
        return currentdate;
    }

</script>

</body>
</html>

